//
//  DoubleDetailsViewController.m
//  CarOfHome2
//
//  Created by 微 醺 on 15/9/29.
//  Copyright (c) 2015年 Frank. All rights reserved.
//

#import "DoubleDetailsViewController.h"
#import "DPartsTableViewCell.h"
#import "ItemModel.h"

@interface DoubleDetailsViewController () <UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong) UIButton *backButton;
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UIImageView *image;


@end

@implementation DoubleDetailsViewController
- (void)viewWillAppear:(BOOL)animated
{
    
    AppDelegate *dele = [[UIApplication sharedApplication]delegate];
    if (dele.isNight == 1) {
        self.view.backgroundColor = [UIColor blackColor];
        self.tableView.backgroundColor = [UIColor blackColor];
        [self.tableView reloadData];
    }
    else{
        self.view.backgroundColor = [UIColor whiteColor];
        self.tableView.backgroundColor = [UIColor whiteColor];
        [self.tableView reloadData];
    }
  
    
    
}
//隐藏StatusBar
- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleDefault;
    //UIStatusBarStyleDefault = 0 黑色文字，浅色背景时使用
    //UIStatusBarStyleLightContent = 1 白色文字，深色背景时使用
}

- (BOOL)prefersStatusBarHidden
{
    return YES; // 返回NO表示要显示，返回YES将hiden
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self tableViewSubview];
    [self logo];
}


- (void)logo
{
    self.backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.backButton.frame = CGRectMake(SAWindth *15, SAHeight * 15, SAWindth *30, SAHeight * 30);
    self.backButton.layer.cornerRadius = 15;
    self.backButton.backgroundColor = [UIColor blackColor];
    self.backButton.alpha = 0.5;
    [self.backButton setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    [self.view addSubview:self.backButton];
    [self.backButton addTarget:self action:@selector(back:) forControlEvents:UIControlEventTouchUpInside];

    
}

- (void)back:(UIButton *)button
{
    [self.navigationController popViewControllerAnimated:YES];
}


- (void)tableViewSubview
{
    self.tableView = [[UITableView alloc] initWithFrame: CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
    self.tableView.rowHeight = SAHeight * 110;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    [self.view addSubview:self.tableView];
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,  300 * SAHeight )];
    self.image = [[UIImageView alloc]init];
    self.image.frame = CGRectMake(0, 0, self.view.frame.size.width,  300 * SAHeight );
    [self.image sd_setImageWithURL:[NSURL URLWithString:self.model.cover] placeholderImage:nil];
    [view addSubview:self.image];
    self.tableView.tableHeaderView = view;
    
    UIView *emptyLine = [[UIView alloc] init];
    emptyLine.backgroundColor = [UIColor clearColor];
    self.tableView.tableFooterView = emptyLine;
    
    [self.tableView registerClass:[DPartsTableViewCell class] forCellReuseIdentifier:@"reuse"];
}

#pragma mark - scrollView 图片下拉放大
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGFloat yy = self.tableView.contentOffset.y;
    if (yy <= 0)
    {
        yy = 0 - yy;
        self.image.frame = CGRectMake(-yy, -yy, self.view.frame.size.width + yy + yy, SAHeight * 300 + yy);
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    DPartsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse"];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    cell.model = self.model;
    
    return cell;
}












- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
